home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cfengine-1.5.3 / src / mount.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-06  |  3.5 KB  |  153 lines

  1. /* cfengine for GNU
  2.  
  3.         Copyright (C) 1995
  4.         Free Software Foundation, Inc.
  5.  
  6.    This file is part of GNU cfengine - written and maintained 
  7.    by Mark Burgess, Dept of Computing and Engineering, Oslo College,
  8.    Dept. of Theoretical physics, University of Oslo
  9.  
  10.    This program is free software; you can redistribute it and/or modify it
  11.    under the terms of the GNU General Public License as published by the
  12.    Free Software Foundation; either version 2, or (at your option) any
  13.    later version.
  14.  
  15.    This program is distributed in the hope that it will be useful,
  16.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.   You should have received a copy of the GNU General Public License
  21.   along with this program; if not, write to the Free Software
  22.   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  23.  
  24. */
  25.  
  26.  
  27. #include "cf.defs.h"
  28. #include "cf.extern.h"
  29.  
  30. /*********************************************************************/
  31. /* Mount support toolkit                                             */
  32. /*********************************************************************/
  33.  
  34. MountPathDefined()
  35.  
  36. {
  37. if (VMOUNTLIST == NULL)
  38.    {
  39.    CfLog(cfinform,"Program does not define mountpattern\n","");
  40.    return false;
  41.    }
  42.  
  43. return true;
  44. }
  45.  
  46. /*********************************************************************/
  47.  
  48.  
  49. MatchAFileSystem(server, lastlink)
  50.  
  51. char *server, *lastlink;
  52.  
  53. { struct Item *mp;
  54.   char *sp;
  55.   char host[maxvarsize];
  56.  
  57. for (mp = VMOUNTED; mp != NULL; mp=mp->next)
  58.    {
  59.    sscanf (mp->name,"%[^:]",host);
  60.  
  61.    if (! IsItemIn(VBINSERVERS,host))
  62.       {
  63.       continue;
  64.       }
  65.  
  66.    if (strcmp(host,VDEFAULTBINSERVER.name) == 0)
  67.       {
  68.       continue;                      /* Can't link machine to itself! */
  69.       }
  70.  
  71.    for (sp = mp->name+strlen(mp->name); *(sp-1) != '/'; sp--)
  72.       {
  73.       }
  74.  
  75.    if (IsHomeDir(sp))
  76.       {
  77.       continue;
  78.       }
  79.  
  80.    if (strcmp(sp,lastlink) == 0)
  81.       {
  82.       strcpy(server,mp->name+strlen(host)+1);
  83.       return(true);
  84.       }
  85.    }
  86.  
  87. return(false);
  88. }
  89.  
  90. /*********************************************************************/
  91.  
  92. IsMountedFileSystem (childstat,dir,rlevel)
  93.  
  94.  /* Is FS NFS mounted ? */
  95.  
  96. char *dir;
  97. struct stat *childstat;
  98. int rlevel;
  99.  
  100. { struct stat parentstat;
  101.   struct Item *ip;
  102.   char host[maxvarsize];
  103.  
  104. for (ip = VMOUNTABLES; ip !=NULL; ip=ip->next)
  105.    {
  106.    if (strstr(ip->name,dir))
  107.       {
  108.       sscanf(ip->name,"%[^:]",host);
  109.  
  110.       Debug("Looking at filesystem %s on %s\n",ip->name,host);
  111.  
  112.       if (strncmp(host,VFQNAME,strlen(host)) == 0)
  113.      {
  114.      Verbose("Filesystem %s belongs to this host\n",dir);
  115.      return false;
  116.      }
  117.       }
  118.    }
  119.   
  120. strcpy(VBUFF,dir);
  121.  
  122. if (VBUFF[strlen(VBUFF)-1] == '/')
  123.    {
  124.    strcat(VBUFF,"..");
  125.    }
  126. else
  127.    {
  128.    strcat(VBUFF,"/..");
  129.    }
  130.  
  131. if (stat(VBUFF,&parentstat) == -1)
  132.    {
  133.    Debug2("File %s couldn't stat its parent directory! Assuming permission\n",dir);
  134.    Debug2("is denied because the file system is mounted from another host.\n");
  135.    return(true);
  136.    }
  137.  
  138. if (rlevel == 0)  /* If this is the root of a search, don't stop before we started ! */
  139.    {
  140.    Debug("NotMountedFileSystem\n");
  141.    return false;
  142.    }
  143.  
  144. if (childstat->st_dev != parentstat.st_dev)
  145.    {
  146.    Debug2("[%s is on a different file system, not descending]\n",dir);
  147.    return (true);
  148.    }
  149.  
  150. Debug("NotMountedFileSystem\n");
  151. return(false);
  152. }
  153.